<!--
 * @Descripttion:
 * @version: 1.0.0
 * @Author: htang
 * @Date: 2023-11-08 09:36:07
 * @LastEditors: htang
 * @LastEditTime: 2024-02-06 10:01:28
-->
<template>
  <div class="app-page">
    <Editor />
    <CommonModal ref="commonModal" />
  </div>
</template>

<script lang="ts" setup>
import { onMounted, getCurrentInstance, nextTick, watch } from 'vue';
import Editor from '@/components/Meta2D/Editor/index.vue';
import CommonModal from '@/components/Meta2D/CommonModal/index.vue';
import IframeModal from '@/components/Meta2D/IframeModal/index.vue';
import { useSelection } from '@/services/selections';
import { stationInfoApi } from '@/api/station';

const { selections } = useSelection();

let { proxy } = getCurrentInstance();

watch(
  () => selections.pen,
  (data) => {
    if (data) {
      let { events } = data;
      if (events) {
        events.some((_: any) => {
          switch (_.action) {
            case 7:
              switch (_.value) {
                case 'l-dialog':
                  {
                    meta2d.on(_.value, (e: any) => {
                      if (proxy.$refs.commonModal) {
                        Object.assign(proxy.$refs.commonModal, {
                          visible: true,
                          title: '自定义弹窗',
                        });
                        nextTick(() => {
                          proxy.$refs.commonModal.init(e);
                        });
                      }
                    });
                  }
                  break;
                case 'iframe-dialog':
                  {
                    meta2d.on(_.value, (e: any) => {
                      if (proxy.$refs.iframeModal) {
                        Object.assign(proxy.$refs.iframeModal, {
                          visible: true,
                          title: '展示',
                          url: _.params,
                        });
                        nextTick(() => {
                          proxy.$refs.iframeModal.init(e);
                        });
                      }
                    });
                  }
                  break;
              }
              break;
          }
        });
      }
    }
  }
);

function onInit() {
  let id = proxy.$route.query.id;
  stationInfoApi({ id }).then((res) => {
    if (res && res['graph']) {
      let data = JSON.parse(res['graph']);
      data['rule'] = false;
      data['locked'] = 1;
      meta2d.open(data);
      meta2d.fitView();
    }
  });
}
onInit();
</script>

<style lang="less" scoped>
.app-page {
  height: 100vh;
}
</style>